<?php

include dirname( __FILE__ )."/header.php";

$lid = isset($_GET['lid']) ? intval($_GET['lid']) : 0;
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
if ( empty($lid) ) {
	die("No lid!");
} elseif ( empty($cid) ) {
	die("No cid!");
}

$result = $xoopsDB->query("select l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description from ".$xoopsDB->prefix($mydirname."_links")." l, ".$xoopsDB->prefix($mydirname."_text")." t where l.lid=$lid and l.lid=t.lid and status>0");

list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result);

if ( empty($lid) ) {
	die("No data! Please check its cid and lid!");
}

$can_qrcode = 0;
if ( $mylinks_can_qrcode == 0 ) {
	$can_qrcode = 0;
}
else if ( $mylinks_can_qrcode == 1) {
	$can_qrcode = 1;
}
else if ( $mylinks_can_qrcode == 2) {
	if ( $xoopsUser ) {
	$can_qrcode =1;
	}
	else {
	$can_qrcode =0;
	}
}
else {
	$can_qrcode = 0;
}

if ( empty($can_qrcode) ) {
	die("Not allowed now!");
}

$myts =& MyTextSanitizer::getInstance();

function mylinks_qrcode_convert_encoding($str, $to = 'SJIS', $from = _CHARSET) 
{
	if (function_exists('mb_convert_encoding')) {
		if (is_array($str)) {
			foreach ($str as $key=>$val) {
				$str[$key] = mylinks_qrcode_convert_encoding($val, $to, $from);
			}
			return $str;
		} else {
			return mb_convert_encoding($str, $to, $from);
		}
	}else {
		return $str;
	}
}

function mylinks_qrcode_encoding($data="") {
$data = mylinks_qrcode_convert_encoding($data);
$data = rawurlencode($data);
$data = ereg_replace("%20", "+", $data);
return $data;
}

$link_data = array();
$link_data['text'] = $myts->makeTareaData4Show($description,0);
$link_data['title'] = $myts->makeTboxData4Show($ltitle);
$link_data['url'] = $myts->makeTboxData4Show($url);
$data = $link_data['title']."\r\n".$link_data['url']."\r\n".$link_data['text'];
$qrcodedata = mylinks_qrcode_encoding($data);
$linkqrcode = "<img alt='qrcode of linkdata' title='qrcode of linkdata'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n<head>\n";
echo "<title>" . $xoopsConfig['sitename'] . "</title>\n";
echo "<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "' />\n";
echo "<meta name='AUTHOR' content='" . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='COPYRIGHT' content='Copyright (c) ".date('Y')." by " . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='DESCRIPTION' content='" . $xoopsConfig['slogan'] . "' />\n";
echo "<meta name='GENERATOR' content='" . XOOPS_VERSION . "' />\n\n\n";
echo "<body bgcolor='#ffffff' text='#000000'>
<div style='width: 750px; border: 1px solid #000; padding: 20px;'>
<div style='text-align: center; display: block; margin: 0 0 6px 0;'>
<h2 style='margin: 0;'>"._MD_MYLINKS_SITETITLE."&nbsp;".$link_data['title']."</h2></div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>"._MD_MYLINKS_SITEURL."&nbsp;:&nbsp;".$link_data['url']."</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>"._MD_MYLINKS_DESCRIPTIONC."<br />".$link_data['text']."</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>LINK DATA QRCODE<br />".$linkqrcode."</div>
<div style='padding-top: 12px; border-top: 2px solid #ccc;'></div>
<p>From: &nbsp;".XOOPSMYLINKURL."/singlelink.php?cid=".$cid."&amp;lid=".$lid."</p>
</div>
<br />";
echo "<br /></body></html>";


?>